#! /usr/bin/env python

import sqlite3
import SQLConn

class InitDB(SQLConn.SQLConn):
	def __init__ (self, DB_File):
		self.db = sqlite3.connect(DB_File).cursor()
		try:
			self.create_table ("Host" ,	"(HOST_ID INTEGER PRIMARY KEY, HOST, PAGE_COUNT INTEGER)")
			self.create_table ("URList" ,	"(URL_ID INTEGER PRIMARY KEY, HOST_ID, PATH, LINKED_COUNT INTEGER , STATUS)")
			# STATUS:
			#	0 - No CONTENT
			#	1 - No LINGUISTIC_VECTOR
			#	2 - Job Completed!
			self.create_table ("Content" ,	"(URL_ID, CONTENT)")
			self.create_table ("Vector" ,	"(URL_ID, LINGUISTIC_VECTOR)")
			self.db.executescript("")
		except:
			pass
		self.Init_URLs()
		self.db.close()

	def Init_URLs(self):
		urls = list()
		for row in self.db.execute("SELECT (URL_ID) FROM URList"):
			urls.append (row)
			break
		if (len(urls) == 0):
			self.insert2table("Host", "(1 ,'chobill.twbbs.org' , 1)")
			self.insert2table("URList", "(1 ,1 , '/' , 1 , '0')")
			self.insert2table("Host", "(2 ,'wordpress.org' , 1)")
			self.insert2table("URList", "(2 ,2 , '/' , 1 , '0')")
			self.insert2table("Host", "(3 ,'www.gnu.org' , 1)")
			self.insert2table("URList", "(3 ,3 , '/' , 1 , '0')")
			self.insert2table("Host", "(4 ,'twitter.com' , 1)")
			self.insert2table("URList", "(4 ,4 , '/' , 1 , '0')")
			self.insert2table("Host", "(5 ,'www.google.com' , 1)")
			self.insert2table("URList", "(5 ,5 , '/' , 1 , '0')")
			self.db.executescript("")

